//
//  OrderDetailViewController.m
//  Doctors
//
//  Created by 王森 on 16/4/11.
//  Copyright © 2016年 王森. All rights reserved.
//

#import "OrderDetailViewController.h"
#import "OrderDetailTableViewCell.h"
#import "OrderModel.h"
@interface OrderDetailViewController ()

@end

@implementation OrderDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
      [self setTextTitleViewWithFrame:CGRectMake(0, 0, 60, 20) title:@"订单详情" fontSize:18];
    [self customTableView];
//    self.tableview.frame=CGRectMake(0, slideControl.bottom, SCREEN_WIDTH, ScreenHeight-64-48-48);
//

    [self addLeftBackBtn:nil];
    
    [self requestData];
    
    UINib *nib=[UIView loadNibNamed:@"OrderDetailTableViewCell" bundle:nil];
    
    [self.tableview registerNib:nib forCellReuseIdentifier:@"OrderDetailTableViewCell"];
    // Do any additional setup after loading the view.
}

-(void)requestData
{
    
    
    [self addProgressHUD];
    
    NSDictionary *dictionary=[NSDictionary dictionaryWithObjectsAndKeys:[self getArtisanId],@"artisanId",_orderId,@"orderId",  nil];
    NSLog(@"订单详情参数：%@",dictionary);
    [[WSNetworkApi shareManager]postWithUrl:@"/order/getOrderInfo" parameters:dictionary option:RequestCenterCachePolicyNormal sucess:^(id responseObject) {
        
        [self removeStatuslable];
        
        NSLog(@"%@",responseObject);
        
        if ([responseObject[@"status"] isEqualToString:@"ok"]) {
            
            OrderModel *model=[[OrderModel alloc]initWithDic:responseObject[@"orderInfo"]];
//            [Singleton shareSingleton].orderId=model.orderId;
            ;

          [self.dataArray addObject:model];

            
        }
        else{
            
            [self showFailed:responseObject[@"message"]];
            
        }

        [self.tableview reloadData];
     
        
    } failur:^(NSError *error) {
      
        
    }];
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //    __weak typeof(self)weakSelf=self;
    //
    //    OrderModel *model=self.dataArray[indexPath.row];
    
    OrderDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"OrderDetailTableViewCell" forIndexPath:indexPath];
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    [cell cellFuzhi:self.dataArray[indexPath.row]];
    
    __weak typeof(self)weakSef=self;
    
    [cell setReRqquest:^{
        [self.dataArray removeAllObjects];
        
        [weakSef requestData];
        
    }];
    
    return cell;
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    OrderModel *model=self.dataArray[indexPath.row];
    NSString *status = [NSString stringWithFormat:@"%d",model.status];
    if (![status isEqualToString:@"0"]&&![status isEqualToString:@"10"]&&![status isEqualToString:@"20"]) {
        return 228;
        
    }
    else
    {
    return 291;;
        
    }

    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
